﻿using System;
using System.Collections.Generic;
using System.Text;
using com.tiyma.common;
namespace com.tiyma.httpmoudle
{
    public class UserToken
    {
        private const string split = "|";

        protected UserToken() { }

        private long _userId;
        private string _userName;
        private string _nickName;
        private string _userIp;


        /// <summary>
        /// 
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="userName"></param>
        /// <param name="ptId"></param>
        /// <param name="sndaId"></param>
        /// <param name="userType"></param>
        /// <param name="nickName"></param>
        /// <param name="loginType"></param>
        public UserToken(long userId, string userName, string nickName)
        {
            this._userId = userId;
            this._userName = userName;
            this._nickName = nickName;
            _userIp =SystemUtil.UserTrueIp;
        }


        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(UserId).Append(split).Append(UserName).Append(split);
            sb.Append(NickName).Append(split).Append(UserIp);
            return sb.ToString();
        }

        public static UserToken ParseToken(string[] arr)
        {
            if (arr == null || arr.Length < 4)
            {
                return null;
            }

            UserToken token = new UserToken(int.Parse(arr[0]), arr[1], arr[2]);
            return token;
        }
        /// <summary>
        /// 用户id
        /// </summary>
        public long UserId
        {
            get { return _userId; }
        }
        /// <summary>
        /// 用户名
        /// </summary>
        public string UserName
        {
            get { return _userName; }
        }
        /// <summary>
        /// 用户IP
        /// </summary>
        public string UserIp
        {
            get
            {
                return _userIp;
            }
        }

        /// <summary>
        /// 用户权限码
        /// </summary>
        public string NickName
        {
            get
            {
                return _nickName;
            }
        }

       
    }
}
